package com.zygh.policeasset.controller;

import cn.hutool.core.util.StrUtil;
import com.zygh.policeasset.component.CommonResult;
import com.zygh.policeasset.pojo.ContractPay;
import com.zygh.policeasset.service.ContractPayService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

@RequestMapping({"/contractpay"})
@Api(tags = {"合同付款模块"})
@RestController
/* loaded from: police-asset-2.0-0.0.1-SNAPSHOT.jar:BOOT-INF/classes/com/zygh/policeasset/controller/ContractPayController.class */
public class ContractPayController {
    @Autowired
    ContractPayService contractPayService;

    @RequestMapping(value = {"/add"}, method = {RequestMethod.POST})
    @ApiOperation("添加合同付款")
    public Object add(@RequestBody ContractPay contractPay) {
        if (StrUtil.isEmpty(contractPay.getContractPayId())) {
            return new CommonResult().validateFailed("项目编号不能为空");
        }
        if (StrUtil.isEmpty(String.valueOf(contractPay.getContractPaySection()))) {
            return new CommonResult().validateFailed("合同id不能为空");
        }
        if (this.contractPayService.add(contractPay).intValue() > 0) {
            return new CommonResult().success();
        }
        return new CommonResult().validateFailed("添加错误");
    }

    @RequestMapping(value = {"/update"}, method = {RequestMethod.POST})
    @ApiOperation("修改合同付款")
    public Object update(@RequestBody ContractPay contractPay) {
        if (StrUtil.isEmpty(String.valueOf(contractPay.getId()))) {
            return new CommonResult().validateFailed("ID不能为空");
        }
        if (this.contractPayService.update(contractPay).intValue() > 0) {
            return new CommonResult().success();
        }
        return new CommonResult().validateFailed("修改错误");
    }

    @RequestMapping(value = {"/remove"}, method = {RequestMethod.GET})
    @ApiOperation("删除合同付款")
    public Object remove(@RequestParam int id) {
        if (StrUtil.isEmpty(String.valueOf(id))) {
            return new CommonResult().validateFailed("id不能为空");
        }
        if (this.contractPayService.remove(id).intValue() > 0) {
            return new CommonResult().success();
        }
        return new CommonResult().validateFailed("删除错误");
    }
}